/************************* 版权声明 *********************************
 * 
 * 版权所有：Apache License 2.0
 * 
 ************************* 版本声明 *********************************
 *@since jdk1.5
 *@version 0.1
 ************************* 变更记录 *********************************
 *
 * 创建者：bijiqiang Email:bijiqiang@gmail.com   创建日期： 2010-1-16
 * 创建记录：创建类结构。
 * 
 * 修改者：       修改日期：
 * 修改记录：
 *
 * 修改者：       修改日期：
 * 修改记录：
 * ……
 ************************* To  Do *********************************
 *
 * 1、实现所有未实现的方法（抛出UnsupportedOperationException的方法）。
 * 
 ************************* 随   笔 *********************************
 *
 * 
 * 
 ******************************************************************
 */

package com.realgodo.site.web.space;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springside.modules.orm.Page;
import org.springside.modules.web.struts2.Struts2Utils;

import com.realgodo.site.entity.application.favorite.Favorite;
import com.realgodo.site.entity.application.show.Show;
import com.realgodo.site.service.application.FavoriteManager;
import com.realgodo.site.service.application.ShowManager;

@Scope("prototype")
public class ShowController extends SpaceDefaultController {
	private static final long serialVersionUID = 4450122430934761028L;

	/** Show.id */
	private Long id;
	private Page<Show> showPage = new Page<Show>(10);
	/** Space.id */
	private Long mySpaceId;

	private Show show;
	@Autowired
	private ShowManager showManager;

	@Autowired
	private FavoriteManager favoriteManager;

	public String execute() throws Exception {
		showPage
				.setPageNo(showManager.isParamNotNull(getParamMap(), Page.PAGE) ? Integer
						.valueOf((String) showManager.getParamValue(
								getParamMap(), Page.PAGE))
						: 1);// 查询页数
		this.showPage = this.showManager.findSpaceShows(showPage, super
				.getVSpace().getId());
		return SUCCESS;
	}

	public String detail() {
		if (null != getId()) {
			show = this.showManager.getShow(getId());
			this.showManager.visitShow(getId());
		}
		return "detail";
	}

	public String comment() {
		this.detail();
		return "comment";
	}

	/**
	 * 加入收藏
	 * 
	 * @return
	 */
	public String favorite() {
		String ok = "2";
		if (null != getId() && null != getMySpaceId()) {
			Favorite favorite = this.favoriteManager.createFavorite(getId(),
					getMySpaceId());
			ok = (null != favorite ? "1" : "2");
		}
		Struts2Utils.renderJson(ok);
		return null;
	}

	public Page<Show> getShowPage() {
		return showPage;
	}

	public void setShowPage(Page<Show> showPage) {
		this.showPage = showPage;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Show getShow() {
		return show;
	}

	public void setShow(Show show) {
		this.show = show;
	}

	public Long getMySpaceId() {
		return mySpaceId;
	}

	public void setMySpaceId(Long mySpaceId) {
		this.mySpaceId = mySpaceId;
	}

}
